package com.qs.controller;


import com.qs.annotation.OperationLog;
import com.qs.pojo.entity.CollectGoods;
import com.qs.pojo.entity.CollectStore;
import com.qs.response.Response;
import com.qs.service.ICollectGoodsService;
import com.qs.service.ICollectStoreService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 用户收藏店铺表 前端控制器
 * </p>
 *
 * @author author
 * @since 2023-12-17
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/collect/store")
@RequiredArgsConstructor
public class CollectStoreController {

    private final ICollectStoreService collectStoreService;

    /**
     * 保存用户收藏的店铺
     * @param collectStore
     * @return
     */
    @PostMapping("/save")
    public Response saveCollectStores(@RequestBody CollectStore collectStore) {
        log.info("保存用户收藏的店铺请求进来了----------");
        collectStoreService.saveCollectStores(collectStore);
        return Response.success();
    }

    /**
     * 查询用户收藏的店铺
     * @param userId
     * @return
     */
    @GetMapping("/list/{pageNo}/{pageSize}/{userId}")
    public Response getCollectStoresList(@PathVariable("pageNo") Integer pageNo,
                                        @PathVariable("pageSize") Integer pageSize,
                                        @PathVariable("userId") Integer userId) {
        log.info("查询用户收藏的店铺的请求进来了----------");
        Map<String,Object> map = collectStoreService.getCollectStoresList(pageNo,pageSize,userId);
        return Response.success(map);
    }

    /**
     * 查询用户买过的店铺
     * @param userId
     * @return
     */
    @GetMapping("/payed/list/{pageNo}/{pageSize}/{userId}")
    public Response getPayedStoresList(@PathVariable("pageNo") Integer pageNo,
                                       @PathVariable("pageSize") Integer pageSize,
                                       @PathVariable("userId") Integer userId) {
        log.info("查询用户买过的店铺的请求进来了----------");
        Map<String,Object> map = collectStoreService.getPayedStoresList(pageNo,pageSize,userId);
        return Response.success(map);
    }

    /**
     * 取消收藏店铺
     * @param id
     * @return
     */
    @DeleteMapping("/cancel/goods/{id}")
    public Response cancelCollectStores(@PathVariable("id") Integer id) {
        log.info("取消收藏店铺的请求进来了----------");
        collectStoreService.removeById(id);
        return Response.success();
    }

}
